<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->
    <!--{include file='comm/comm_editor.tpl'}-->
    <title><!--{if $operFlg == 3}-->修改<!--{else}-->添加<!--{/if}-->自定义模板</title>
    <!--{include file="comm/icheck.tpl"}-->
    <style>
        #typeShow {
            width:710px;!important
        }
    </style>
</head>
<body>
<div class="panel panel-default">

    <div class="panel-heading">
        <h2 style="" class="tal">正在操作：<!--{if $operFlg == 3}-->修改<!--{else}-->添加<!--{/if}-->自定义模板</h2>
    </div>
    <div class="panel-body">



        <form id="item_form" onsubmit="return false;" class="form-horizontal">

            <div class="form-group">
                <label class="col-sm-2 control-label" for="templateName">
                    <span class="red">*</span>
                    模板名称：
                </label>
                <div class="col-sm-10">
                    <input id="templateName" class="form-control w300" type="text" placeholder="请输入模板名称" value="<!--{$templateMsg.templateName|default:''}-->" name="templateName">
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-2 control-label" for="templateAlias">
                    <span class="red">*</span>
                    模板别名：
                </label>
                <div class="col-sm-10">
                    <!--{if isset($templateMsg)}-->
                    <p class="form-control-static"><!--{$templateMsg.templateAlias|default:''}--></p>
                    <input id="templateAlias" class="form-control w300" type="text" style="display: none;" name="templateAlias" value="<!--{$templateMsg.templateAlias|default:''}-->">
                    <!--{else}-->
                    <input id="templateAlias" class="form-control w300" type="text" placeholder="请输入模板别名" name="templateAlias" value="">
                    <!--{/if}-->
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-2 control-label" for="content">
                    选项：
                </label>
                <div class="col-sm-10">
                    <p class="form-control-static">
                        <a style="float:left;" onclick="messageTemplate.commbinStr('bill_no')" href="javascript:void(0);">订单号</a>
                        <a style="float:left;margin-left:10px;" onclick="messageTemplate.commbinStr('bill_code')" href="javascript:void(0);">订单编号</a>
                        <a style="float:left;margin-left:10px;" onclick="messageTemplate.commbinStr('bill_status')" href="javascript:void(0);">订单状态</a>
                        <a style="float:left;margin-left:10px;" onclick="messageTemplate.commbinStr('operator')" href="javascript:void(0);">操作者</a>
                        <a style="float:left;margin-left:10px;" onclick="messageTemplate.commbinStr('custID')" href="javascript:void(0);">会员名</a>
                        <a style="float:left;margin-left:10px;" onclick="messageTemplate.commbinStr('mobile')" href="javascript:void(0);">手机号码</a>
                        <a style="float:left;margin-left:10px;" onclick="messageTemplate.commbinStr('phone')" href="javascript:void(0);">电话</a>
                        <a style="float:left;margin-left:10px;" onclick="messageTemplate.commbinStr('address')" href="javascript:void(0);">地址</a>
                        <a style="float:left;margin-left:10px;" onclick="messageTemplate.commbinStr('cus_name')" href="javascript:void(0);">会员姓名</a>
                        <a style="float:left;margin-left:10px;" onclick="messageTemplate.commbinStr('date')" href="javascript:void(0);">当前日期</a>
                        <a style="float:left;margin-left:10px;" onclick="messageTemplate.commbinStr('date_time')" href="javascript:void(0);">当前时间</a>
                        <a style="float:left;margin-left:10px;" onclick="messageTemplate.commbinStr('send_time')" href="javascript:void(0);">配送时间</a>
                        <a style="float:left;margin-left:10px;" onclick="messageTemplate.commbinStr('distribution_technician')" href="javascript:void(0);">配送员</a>
                        <a style="float:left;margin-left:10px;" onclick="messageTemplate.commbinStr('distribution_name')" href="javascript:void(0);">配送站</a>
                        <a style="float:left;margin-left:10px;" onclick="messageTemplate.commbinStr('pwd')" href="javascript:void(0);">密码</a>
                        <a style="float:left;margin-left:10px;" onclick="messageTemplate.commbinStr('sms_yzm')" href="javascript:void(0);">短信验证码</a>
                        <a style="float:left;margin-left:10px;" onclick="messageTemplate.commbinStr('remark')" href="javascript:void(0);">内部留言</a>
                    </p>
                </div>

            </div>

            <div class="form-group">
                <label class="col-sm-2 control-label" for="content">
                    <span class="red">*</span>
                    内容：
                </label>
                <div class="col-sm-10" id="typeShow" >
                    <textarea class="form-control w300" rows="3" name="content" id="content"><!--{$templateMsg.content|default:''}--></textarea>
                    <input type="hidden" name="templateID" value="<!--{$templateMsg.templateID|default:''}-->" />
                    <input type="hidden" class="square-radio" id="square-radio-1" name="type" value="1" checked />
                </div>
            </div>


        </form>


    </div>



    <div class="bottom_fixbox">
        <div class="tac" style="background: #dddddd;">
            <input type="button" class="btn btn-primary" onclick="messageTemplate.check();" value="保存" />&nbsp;&nbsp;&nbsp;
            <input type="button" class="btn btn-default" onclick="E.closeWindows();" value="关闭" />
        </div>
    </div>


</div>

<script type="text/javascript">


    $(document).ready(function(){



        $('.square-radio').iCheck({
            checkboxClass: 'icheckbox_square-blue',
            radioClass: 'iradio_square-blue',
            increaseArea: '20%' // optional
        });



    });
    var messageTemplate = {

        //组合字符串
        commbinStr:function( params ){

            var value = $("#content").val();

            var combineChar = value + '\$' + params;

            $("#content").val(combineChar);
            $("#content").focus();

        },

        operFlg:<!--{$operFlg}-->,



        //检查数据
        check: function() {

            this.dt = E.getFormValues("item_form");

            var error_msg = "";
            if (this.dt.templateName == ""){
                error_msg +=  "模板名称不能为空<br />";
            }

            if (this.dt.templateAlias == ""){
                error_msg +=  "模板别名不能为空<br />";
            }



            if ((this.dt.content == "" || this.dt.content =="<br>")){
                error_msg +=  "内容不能为空<br />";
            }

            if (error_msg != "")
                E.alert(error_msg);
            else
                messageTemplate.addConfirm();
        },

        addConfirm:function(){
            if(messageTemplate.operFlg == 2){
                E.confirm("您确认添加自定义模板吗？", "messageTemplate.add");
            }else{
                E.confirm("您确认修改自定义模板吗？", "messageTemplate.add");
            }

        },

        //保存信息
        add: function() {
            $.ajax({
                type: "POST",
                url: "/invokingAjax-backend/system/messageTemplate.ajax?operFlg=2",
                dataType: "JSON",
                data: this.dt,
                success: function( result_obj ) {
                    if (result_obj.code == 200) {
                        E.opener("messageTemplate.load");
                        if (messageTemplate.operFlg == 3){ //编辑
                            E.alert(result_obj.message, 2, "E.closeWindows");
                        }else if (messageTemplate.operFlg == 2){ //添加
                            E.alert(result_obj.message, 2,"E.refresh");
                        }
                    } else {
                        E.alert(result_obj.message);
                    }
                }
            });
        }

    };

</script>

</body>

</html>
